#import "BaichuanPlugin.h"
#import "BaichuanPlugin+handler.h"
#import <AlibcTradeUltimateSDK/AlibcTradeUltimateSDK.h>

@interface BaichuanPlugin()<FlutterStreamHandler>
@property(nonatomic,strong)FlutterMethodChannel* channel;
@end
@implementation BaichuanPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"com.qiaomeng.flutter/baichuan"
            binaryMessenger:[registrar messenger]];
    BaichuanPlugin* instance = [[BaichuanPlugin alloc] init];
    instance.channel = channel;
  [registrar addMethodCallDelegate:instance channel:channel];
    [registrar addApplicationDelegate:instance];
    
    
    
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveAliMessage:) name:@"receiveAliMessage" object:nil];
    }
    return self;
}
- (void)receiveAliMessage:(NSNotification*)notification{
    printf(@"%@",notification.object);
    //registerNavigateUrl
    [self.channel invokeMethod:@"registerNavigateUrl" arguments:notification.object];
    

}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  }else if([@"debug" isEqualToString:call.method]){
      [self debug:result];
  }else if([@"asyncInit" isEqualToString:call.method]){
      [self asyncInit:call result:result];
  }else if([@"setIsvVersion" isEqualToString:call.method]){
      
  }else if([@"showLogin" isEqualToString:call.method]){
      [self showLogin:call result:result];
  }else if([@"logout" isEqualToString:call.method]){
      
  }else if([@"isLogin" isEqualToString:call.method]){
      [self isLogin:call result:result];
      
  }else if([@"getUserInfo" isEqualToString:call.method]){
      
  }else if([@"openByCode" isEqualToString:call.method]){
      [self openByCode:call result:result];
  }else if([@"openByUrl" isEqualToString:call.method]){
      [self openByUrl:call result:result];
      
  }else if([@"registerNavigateUrl" isEqualToString:call.method]){
      
  }else if([@"registerImage" isEqualToString:call.method]){
      
  }else {
    result(FlutterMethodNotImplemented);
  }
}

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
    return [[AlibcTradeUltimateSDK sharedInstance] application:application openURL:url options:options];
}
@end
